<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span><strong>新闻通知</strong></span>
            </div>
        </template>
        <el-form inline>
               <br>
               <br>
        </el-form>
        <!-- 新闻列表 -->
        <el-table
                v-loading="loading"
                element-loading-text="Loading..."
                :element-loading-spinner="svg"
                element-loading-svg-view-box="-10, -10, 50, 50"
                :data="fileData"
                style="width: 100%">
                <el-table-column type="index" width="300" label="序号"></el-table-column>
                <el-table-column label="标题" prop="title"  width="auto"></el-table-column>
                <el-table-column label="发布日期" prop="publishTime" width="auto" ></el-table-column>
                <el-table-column label="发布人" prop="author"></el-table-column>
                <el-table-column label="发布人单位"  width="auto" >体育部</el-table-column>
                <el-table-column label="相关附件" prop="fileName"show-overflow-tooltip>
                    <template #default="{ row }">
                        <el-tooltip content="点击下载" effect="light">
                    <el-link type="primary" :href="row.fileUrl" target="_blank" :download="row.fileName"
                    :underline="false" @click="down">
                        {{ row.fileUrl?row.fileName:"" }}
                    </el-link>
                        </el-tooltip>
                </template>
            </el-table-column>
            <template #empty>
                <el-empty description="未查找到数据" />
            </template>
        </el-table>
         <!-- 分页条 -->
          <br><br><br><br><br><br>
         <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[6, 8 ,10]"
            layout="jumper, total, sizes, prev, pager, next" background :total="total" @size-change="onSizeChange"
            @current-change="onCurrentChange" style="margin-top: 20px; justify-content: flex-end" />
    </el-card>
</template>
<script setup>
//导入token状态
import { useTokenStore } from '@/stores/token.js'
import {ElMessage,ElMessageBox} from 'element-plus'
import {ref,onMounted} from 'vue'
import {getPageService,addFile,deleteByNewID} from'@/api/public/newsFile.js'
//分页条数据模型
const currentPage = ref(1)//当前页
const total = ref(0)//总条数
const pageSize = ref(3)//每页条数
//分页表表数据模型
const fileData=ref()
const loading=ref(true)
//分页获取函数
const getPage= async ()=>{
    const model={
        currentPage:currentPage.value,
        pageSize:pageSize.value
    }
    let result=await getPageService(model)
    fileData.value=result.data.records
    total.value=result.data.total
    loading.value=false
}
//页面加载时函数
onMounted(
    ()=>{
        getPage()
    }
)
//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
    pageSize.value = size
    getPage()
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
    currentPage.value = num
    getPage()
}
const down=()=>{
    ElMessage.success("下载成功！")
}
</script>
<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;
    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>